var provinceArray = [{id:"1",name:"四川"},
    {id:"2",name:"湖南"},
    {id:"3",name:"云南"}];
var cityArray = [{id:"1",name:"成都",idP:"1"},
    {id:"2",name:"南充",idP:"1"},{id:"3",name:"巴中",idP:"1"},
    {id:"4",name:"长沙",idP:"2"},
    {id:"5",name:"株洲",idP:"2"},{id:"6",name:"衡阳",idP:"2"},
    {id:"7",name:"丽江",idP:"3"},
    {id:"8",name:"大理",idP:"3"},{id:"9",name:"洱海",idP:"3"}, ];
$(function () {
    for(var i=0;i<provinceArray.length;i++){
        var pro = provinceArray[i];
        var option = document.createElement("option");
        option.innerHTML=`${pro.name}`;
        option.value=pro.id;
        $("#province").append(option);
    }
    $("#province").change(function () {
        changeCity( $("#province").val());
    });
    changeCity(provinceArray[0].id);
})
function changeCity(pVal) {
    $("#city").html("");
    for(var i=0;i<cityArray.length;i++){
        var city = cityArray[i];
        if(city.idP == pVal){
            var option = document.createElement("option");
            option.innerHTML=`${city.name}`;
            option.value=city.id;
            $("#city").append(option);
        }
    }
}